From 506132d3edc8d062f65fdacf007a15613d27e5c5 Mon Sep 17 00:00:00 2001
From: Eneas U de Queiroz <cotequeiroz@gmail.com>
Date: Wed, 6 Apr 2022 09:49:48 -0300
Subject: [PATCH] man: add option to skip building man pages

Add a 'skip_manpages' option to meson, so that man pages do not get
built.

Signed-off-by: Eneas U de Queiroz <cotequeiroz@gmail.com>
[Retrieved from: https://github.com/latchset/jose/pull/115]
Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
---
 meson.build       | 24 +++++++++++++-----------
 meson_options.txt |  1 +
 2 files changed, 14 insertions(+), 11 deletions(-)
 create mode 100644 meson_options.txt

diff --git a/meson.build b/meson.build
index 1edfbe7..9b40efb 100644
--- a/meson.build
+++ b/meson.build
@@ -37,7 +37,6 @@ zlib = dependency('zlib')
 threads = dependency('threads')
 jansson = dependency('jansson', version: '>=2.10')
 libcrypto = dependency('libcrypto', version: '>=1.0.2')
-a2x = find_program('a2x', required: false)
 
 mans = []
 
@@ -63,14 +62,17 @@ pkg.generate(
   requires: 'jansson',
 )
 
-if a2x.found()
-  foreach m : mans
-    custom_target(m.split('/')[-1], input: m + '.adoc', output: m.split('/')[-1],
-      command: [a2x, '-f', 'manpage', '-D', meson.current_build_dir(), '@INPUT@'],
-      install_dir: join_paths(get_option('mandir'), 'man' + m.split('.')[-1]),
-      install: true
-    )
-  endforeach
-else
-  warning('Will not build man pages due to missing dependencies!')
+if not get_option('skip_manpages')
+  a2x = find_program('a2x', required: false)
+  if a2x.found()
+    foreach m : mans
+      custom_target(m.split('/')[-1], input: m + '.adoc', output: m.split('/')[-1],
+        command: [a2x, '-f', 'manpage', '-D', meson.current_build_dir(), '@INPUT@'],
+        install_dir: join_paths(get_option('mandir'), 'man' + m.split('.')[-1]),
+        install: true
+      )
+    endforeach
+  else
+    warning('Will not build man pages due to missing dependencies!')
+  endif
 endif
diff --git a/meson_options.txt b/meson_options.txt
new file mode 100644
index 0000000..0885515
--- /dev/null
+++ b/meson_options.txt
@@ -0,0 +1 @@
+option('skip_manpages', type: 'boolean', value: false, description: 'Do not build manpages')
